package com.toy.base.domain;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import com.toy.core.domain.BaseObject;
import com.toy.core.util.LabelValue;

@Document(collection="T_USER")
public class User implements BaseObject {
	
	public static int STATE_NORMAL = 0;
	public static int STATE_DELETE = 1;
	public static int STATE_FORBID = 2;
	private static Map<Integer,LabelValue> stateValues = new HashMap<Integer,LabelValue>();
	static{
		stateValues.put(STATE_NORMAL, new LabelValue("正常",String.valueOf(STATE_NORMAL)));
		stateValues.put(STATE_DELETE, new LabelValue("删除",String.valueOf(STATE_DELETE)));
		stateValues.put(STATE_FORBID, new LabelValue("禁用",String.valueOf(STATE_FORBID)));
	}
	
	private static final long serialVersionUID = -5379203400713000463L;
	@Id
	private long id;
	@Indexed(unique=true)
	private String username;//登陆名
	private String password;//密码
	private String realName;//显示名
	@Indexed
	private int state;//状态
	private Date regDate;//注册日期
	private String ipAddress;//注册IP
	
	public String toString() {
		return new ToStringBuilder(this).append("id", id).append("username",
				username).append("password", password).append("realName",
				realName).append("state", state).append("regDate", regDate)
				.toString();
	}
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}
	public int getState() {
		return state;
	}
	public void setState(int state) {
		this.state = state;
	}
	public Date getRegDate() {
		return regDate;
	}
	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	public String getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}
	
	public LabelValue getUserStateValue(){
		return stateValues.get(this.state);
	}
	
	public static Collection<LabelValue> getUserStateValues(){
		return stateValues.values();
	}	
}
